package com.zhangjun.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.DriverManagerDataSource;


/**
 * @author 张钧
 * @Description
 * @create 2022-09-27 17:16
 */
@Configuration
public class DatabaseConfiguration {

    @Bean
    public DriverManagerDataSource driverManagerDataSource() {
        return new DriverManagerDataSource(
                "jdbc:mysql://localhost:3306/spring",
                "root","072900");
    }

    @Bean
    public JdbcTemplate jdbcTemplate(DriverManagerDataSource driverManagerDataSource){
        return new JdbcTemplate(driverManagerDataSource);
    }

    @Bean(name = "transactionManager")
    public DataSourceTransactionManager dataSourceTransactionManager(DriverManagerDataSource driverManagerDataSource){
        return new DataSourceTransactionManager(driverManagerDataSource);
    }
}
